<template>
  <coin-tr :coin_type="coin_type" :shares="shares" :shares_unit="shares_unit" :coin_data="coin_data" :href="preHelpHref+'/articles/360015486632'">
    <echarts ref="echarts" class="index-echarts" :option="echartsOptions" />
  </coin-tr>
</template>

<script>
import {
  poolStatsD,
  poolStats,
} from '@/api';
import { mapGetters } from 'vuex';
import indexTable from './base/trMixin';

export default {
  mixins: [indexTable],
  data() {
    return {
      coin_type: 'btc',
      shares_unit: '',
    };
  },
  computed: {
    ...mapGetters(['language']),
    preHelpHref() {
      return `https://support.dpool.top/hc/${this.language === 'zh' ? 'zh-cn' : 'en-us'}`;
    },
  },
  methods: {
    getHistoryStats() {
      poolStatsD().then((res) => {
        if (res.data.status === 1) {
          const data = res.data.data;
          this.echartsOptions.xAxis.data = data.tm.slice(-7);
          this.echartsOptions.series[0].data = data.sl.slice(-7);
          if (this.$refs.echarts) {
            this.$refs.echarts.setOption(this.echartsOptions);
          }
        }
      });
    },
    getStats() {
      poolStats().then((res) => {
        if (res.data.status === 1) {
          this.shares = res.data.data.hash_rate;
          this.shares_unit = res.data.data.shares.shares_unit;
        }
      });
    },
  },
};
</script>

